//
//  BaseNavigationController.m
//  Custom_Weibo
//
//  Created by LEO on 12/7/15.
//  Copyright © 2015 Leo_Lei. All rights reserved.
//

#import "BaseNavigationController.h"

@interface BaseNavigationController ()

@end

@implementation BaseNavigationController

#pragma mark - SYSTEM_METHODS
- (void)viewDidLoad {
    [super viewDidLoad];
    [self loadImage];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - INITIALIZATION_METHODS
- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        [self getNotification];
    }
    return self;
}

- (instancetype)initWithCoder:(NSCoder *)aDecoder {
    self = [super initWithCoder:aDecoder];
    if (self) {
        [self getNotification];
    }
    return self;
}

#pragma mark - MONITOR_NOTIFICATION
- (void)getNotification {
    //  Monitoring the notification.
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(themeDidChange:)
                                                 name:kThemeNotification
                                               object:nil];
}

#pragma mark - WHEN_THEME_CHANGED
- (void)themeDidChange:(NSNotification *)notification {
    [self loadImage];
}

#pragma mark SET_IMAGE
- (void)loadImage {
    NSString *navImageName = @"mask_titlebar.png";
    if (DEVICE_AVALIABLE_IOS7) {
        navImageName = @"mask_titlebar64.png";
    }
    
    UIImage *image = [[ThemeManager defaultManager] getThemeImage:navImageName];
    [self.navigationBar setBackgroundImage:image forBarMetrics:UIBarMetricsDefault];
    
    UIColor *titleColor = [[ThemeManager defaultManager] getThemeColor:@"Mask_Title_color"];
    self.navigationBar.titleTextAttributes = @{
                                               NSForegroundColorAttributeName:titleColor,
                                               NSFontAttributeName:[UIFont boldSystemFontOfSize:18]
                                               };
}

#pragma mark - DEALLOC
- (void)dealloc {
    //Remove observer.
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
